package org.leetcode.easy.leetcode283;

import java.util.Arrays;

public class Solution {

    public void moveZeroes3(int[] nums) {
        int n = nums.length;

        int slow = 0;
        int fast = 0;

        for (fast = 0; fast < n; fast++) {
            if (nums[fast]!=0){
                nums[slow]=nums[fast];
                slow++;
            }
        }

        for (int i = slow; i < n ; i++) {
            nums[i]=0;
        }
    }

    public void moveZeroes2(int[] nums) {

        int left = 0;
        int right = 0;


        while (right < nums.length) {
            if (nums[right] != 0) {
                if (left != right) {
                    nums[left] = nums[right];
                    nums[right] = 0;
                }
                left++;
            }
            right++;
        }

    }


    public static void moveZeroes(int[] nums) {
        int slow = 0;


        for (int fast = 0; fast < nums.length; fast++) {

            if (nums[fast] != 0 && fast != slow) {
                nums[slow] = nums[fast];
                nums[fast] = 0;
                slow++;
            }

        }


    }


    public static void main(String[] args) {
//        int []nums = {0,1,0,3,12};
        int[] nums = {1, 0, 0};
        moveZeroes(nums);

        System.out.println(Arrays.toString(nums));

    }
}
